#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,l,V;
int d[N],v[N],a[N],p[N];
void solve(){
    cin>>n>>m>>l>>V;
    int min_d=-1e9;
    for(int i=1;i<=n;i++){
        cin>>d[i]>>v[i]>>a[i];
        min_d=min(min_d,d[i]);
    }
    int max_p=-1e9;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        max_p=max(max_p,p[i]);
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
        if(d[i]<=max_p&&v[i]>V) cnt++;
    cout<<cnt<<" ";
    if(!cnt){
        cout<<m<<"\n";
        return;
    }
    int res=0;
    for(int i=1;i<=m;i++)
        if(p[i]>min_d) res++;
    res--;
    cout<<res<<"\n";
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T;
    cin>>T;
    while(T--) solve();
    return 0;
}